<template>
  <div class="bus-child2">
    <h3>BusChild2 组件</h3>
    <p>这个组件会监听来自 BusChild1 的事件，并显示接收到的消息。</p>
    <div>接收到的消息:</div>
    <div style="color: red; font-weight: bold">{{ message }}</div>
  </div>
</template>

<script setup lang="ts">
import { getCurrentInstance, onMounted, ref } from 'vue'

const message = ref('暂无消息')
const instance = getCurrentInstance()
onMounted(() => {
  instance?.proxy?.$bus.on('message-from-child1', (msg: string) => {
    message.value = msg
  })
})
</script>

<style scoped lang="scss"></style>
